-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support sum(LinearMixin) #8722
Conversation
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the the following people are requested to review this:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mathematics aside, this looks good to me. It wouldn't hurt to have a feature release note saying that "BaseOperator
subclasses (like x, y and z) can now be used with sum
" - the magic methods aren't in the documentation, but the effects can still be seen by users.
93a4b2c
to
bdbadc3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe to test __rsub__
we just call the method directly? We can compare a.__sub__(b)
and b.__rsub__(a)
. I think we can trust Python to do the magic delegation correctly, so manually calling seems cleanest. The reason to have more than 0 - a
is because that wouldn't have caught the original typo.
This enables the use of `sum(...)` for subclasses of the `LinearMixin` class. It also adds the reflective operand dunder methods `__radd__` and `__rsub__`.
bdbadc3
to
2e02589
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks Max. I pushed a commit to add the Sphinx crossrefs to the release note, and we're good to go.
Thanks, Jake, for the speedy review process! 🙏 |
Pull Request Test Coverage Report for Build 3022252832
💛 - Coveralls |
LGTM (after merged haha) |
Sorry - I thought it'd be inconsequential enough not to need to worry you about it! (And I didn't expect you to be at work at 23:00...) |
* feat: support sum(LinearMixin) This enables the use of `sum(...)` for subclasses of the `LinearMixin` class. It also adds the reflective operand dunder methods `__radd__` and `__rsub__`. * Add crossreferences to release note Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
* Rewrite Amplitude Estimators with Primitives * Update qiskit/algorithms/amplitude_estimators/ae.py Co-authored-by: Julien Gacon <gaconju@gmail.com> * fix errors * Update qiskit/algorithms/amplitude_estimators/ae.py Co-authored-by: dlasecki <dal@zurich.ibm.com> * Update qiskit/algorithms/amplitude_estimators/fae.py Co-authored-by: dlasecki <dal@zurich.ibm.com> * Update qiskit/algorithms/amplitude_estimators/fae.py Co-authored-by: dlasecki <dal@zurich.ibm.com> * Update qiskit/algorithms/amplitude_estimators/iae.py Co-authored-by: dlasecki <dal@zurich.ibm.com> * fix annotations * Add sampler properties * refactor evaluate_measurements * deprecate qiskit.pulse.utils.deprecated_functionality in favor of qiskit.utils.deprecation.deprecate_function (#8696) * deprecate deprecated_functionality * pylint: disable=cyclic-import * Add reno * Include Terra version in deprecation notice Co-authored-by: Jake Lishman <jake.lishman@ibm.com> * feat: support sum(LinearMixin) (#8722) * feat: support sum(LinearMixin) This enables the use of `sum(...)` for subclasses of the `LinearMixin` class. It also adds the reflective operand dunder methods `__radd__` and `__rsub__`. * Add crossreferences to release note Co-authored-by: Jake Lishman <jake.lishman@ibm.com> * set shots on fae sampler * cache circuits during estimate * Change algos estimate * Change from run_options ro options * remove circuits cache list * Update qiskit/algorithms/amplitude_estimators/ae.py Co-authored-by: dlasecki <dal@zurich.ibm.com> * Update qiskit/algorithms/amplitude_estimators/ae_utils.py Co-authored-by: dlasecki <dal@zurich.ibm.com> * change slice * Get shots from metadata * Update qiskit/algorithms/amplitude_estimators/iae.py Co-authored-by: dlasecki <dal@zurich.ibm.com> * Rearrange annotation None * Update qiskit/algorithms/amplitude_estimators/ae.py Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> * Fix deprecation msg Co-authored-by: Julien Gacon <gaconju@gmail.com> Co-authored-by: dlasecki <dal@zurich.ibm.com> Co-authored-by: Luciano Bello <bel@zurich.ibm.com> Co-authored-by: Jake Lishman <jake.lishman@ibm.com> Co-authored-by: Max Rossmannek <oss@zurich.ibm.com> Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* Rewrite Amplitude Estimators with Primitives * Update qiskit/algorithms/amplitude_estimators/ae.py Co-authored-by: Julien Gacon <gaconju@gmail.com> * fix errors * Update qiskit/algorithms/amplitude_estimators/ae.py Co-authored-by: dlasecki <dal@zurich.ibm.com> * Update qiskit/algorithms/amplitude_estimators/fae.py Co-authored-by: dlasecki <dal@zurich.ibm.com> * Update qiskit/algorithms/amplitude_estimators/fae.py Co-authored-by: dlasecki <dal@zurich.ibm.com> * Update qiskit/algorithms/amplitude_estimators/iae.py Co-authored-by: dlasecki <dal@zurich.ibm.com> * fix annotations * Add sampler properties * refactor evaluate_measurements * deprecate qiskit.pulse.utils.deprecated_functionality in favor of qiskit.utils.deprecation.deprecate_function (Qiskit#8696) * deprecate deprecated_functionality * pylint: disable=cyclic-import * Add reno * Include Terra version in deprecation notice Co-authored-by: Jake Lishman <jake.lishman@ibm.com> * feat: support sum(LinearMixin) (Qiskit#8722) * feat: support sum(LinearMixin) This enables the use of `sum(...)` for subclasses of the `LinearMixin` class. It also adds the reflective operand dunder methods `__radd__` and `__rsub__`. * Add crossreferences to release note Co-authored-by: Jake Lishman <jake.lishman@ibm.com> * set shots on fae sampler * cache circuits during estimate * Change algos estimate * Change from run_options ro options * remove circuits cache list * Update qiskit/algorithms/amplitude_estimators/ae.py Co-authored-by: dlasecki <dal@zurich.ibm.com> * Update qiskit/algorithms/amplitude_estimators/ae_utils.py Co-authored-by: dlasecki <dal@zurich.ibm.com> * change slice * Get shots from metadata * Update qiskit/algorithms/amplitude_estimators/iae.py Co-authored-by: dlasecki <dal@zurich.ibm.com> * Rearrange annotation None * Update qiskit/algorithms/amplitude_estimators/ae.py Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> * Fix deprecation msg Co-authored-by: Julien Gacon <gaconju@gmail.com> Co-authored-by: dlasecki <dal@zurich.ibm.com> Co-authored-by: Luciano Bello <bel@zurich.ibm.com> Co-authored-by: Jake Lishman <jake.lishman@ibm.com> Co-authored-by: Max Rossmannek <oss@zurich.ibm.com> Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* Rewrite Amplitude Estimators with Primitives * Update qiskit/algorithms/amplitude_estimators/ae.py Co-authored-by: Julien Gacon <gaconju@gmail.com> * fix errors * Update qiskit/algorithms/amplitude_estimators/ae.py Co-authored-by: dlasecki <dal@zurich.ibm.com> * Update qiskit/algorithms/amplitude_estimators/fae.py Co-authored-by: dlasecki <dal@zurich.ibm.com> * Update qiskit/algorithms/amplitude_estimators/fae.py Co-authored-by: dlasecki <dal@zurich.ibm.com> * Update qiskit/algorithms/amplitude_estimators/iae.py Co-authored-by: dlasecki <dal@zurich.ibm.com> * fix annotations * Add sampler properties * refactor evaluate_measurements * deprecate qiskit.pulse.utils.deprecated_functionality in favor of qiskit.utils.deprecation.deprecate_function (Qiskit/qiskit#8696) * deprecate deprecated_functionality * pylint: disable=cyclic-import * Add reno * Include Terra version in deprecation notice Co-authored-by: Jake Lishman <jake.lishman@ibm.com> * feat: support sum(LinearMixin) (Qiskit/qiskit#8722) * feat: support sum(LinearMixin) This enables the use of `sum(...)` for subclasses of the `LinearMixin` class. It also adds the reflective operand dunder methods `__radd__` and `__rsub__`. * Add crossreferences to release note Co-authored-by: Jake Lishman <jake.lishman@ibm.com> * set shots on fae sampler * cache circuits during estimate * Change algos estimate * Change from run_options ro options * remove circuits cache list * Update qiskit/algorithms/amplitude_estimators/ae.py Co-authored-by: dlasecki <dal@zurich.ibm.com> * Update qiskit/algorithms/amplitude_estimators/ae_utils.py Co-authored-by: dlasecki <dal@zurich.ibm.com> * change slice * Get shots from metadata * Update qiskit/algorithms/amplitude_estimators/iae.py Co-authored-by: dlasecki <dal@zurich.ibm.com> * Rearrange annotation None * Update qiskit/algorithms/amplitude_estimators/ae.py Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> * Fix deprecation msg Co-authored-by: Julien Gacon <gaconju@gmail.com> Co-authored-by: dlasecki <dal@zurich.ibm.com> Co-authored-by: Luciano Bello <bel@zurich.ibm.com> Co-authored-by: Jake Lishman <jake.lishman@ibm.com> Co-authored-by: Max Rossmannek <oss@zurich.ibm.com> Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Summary
This enables the use of
sum(...)
for subclasses of theLinearMixin
class. It also adds the reflective operand dunder methods__radd__
and__rsub__
.Details and comments
Since this is not part of the publicly documented API, I did not add a reno.